package tech.aistar.design.factory.version06;

/**
 * 本类用来演示: 基于简单工厂设计模式改造的反射工厂
 *
 * @author: success
 * @date: 2022/7/25 3:01 下午
 */
public class Factory {
    public static Object getInstance(String className){
        Object obj = null;

        //1. 获取类的class实例
        try {
            Class<?> c = Class.forName(className);

            //2. 反射调用构造 - 反射构建对象
            obj = c.newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }

        return obj;

    }
}
